40923248 cp2020

  • Home
    • Site Map
    • reveal
    • blog
  • 首YA
  • HW1
    • PCH 15 Introduction to Wireless Networking 無線網絡簡介
      • Wireless LANs 無線局域網
      • Wireless Devices 無線設備
      • Wireless Standards 無線標準
      • Privacy and Security 隱私和安全
      • Wireless Networking Types 無線網絡類型
    • PCH 16  Internet Connectivity 互聯網連接
      • Internet Connectivity 互聯網連接
      • Networking  Internet Connectivity  聯網 Internet連接
      • Setting up a Network 建立網絡
  • HW2
  • HW3
    • Birthday Dictionaries 生日字典
      • Exercise 33  and Solution   練習33 和解決方案
      • Discussion topics 討論主題
      • Dictionaries 辭典
      • QUICK REVIEW 快速復審
      • MORE ON DICTIONARY KEYS 有關字典鍵的更多信息
      • String formatting 字符串格式
      • Solutions 解決方案
    • Tic Tac Toe Draw 井字遊戲抽獎
      • Exercise 27 and Solution 練習27 和解決方案
      • Concepts 概念
      • Solutions解決方案
    • Birthday Plots 生日情節
      • Exercise 36 and Solution 練習36和解決方案
      • Discussion 討論區
      • When to make plots 什麼時候作圖
      • Plotting libraries in Python 用Python繪製庫
      • Installing bokeh 安裝背景虛化
      • Using bokeh 使用散景
  • 心得
  • 自評 65 分
String formatting 字符串格式 << Previous Next >> Tic Tac Toe Draw 井字遊戲抽獎

Solutions 解決方案

This exercise is Part 1 of 4 of the birthday data exercise series. The other exercises are: Part 2, Part 3, and Part 4.

For this exercise, we will keep track of when our friend’s birthdays are, and be able to find that information based on their name. Create a dictionary (in your file) of names and birthdays. When you run your program it should ask the user to enter a name, and return the birthday of that person back to them. The interaction should look something like this:

此練習是生日數據練習系列4的第1部分。其他練習是:第2部分,第3部分和第4部分。

在本練習中,我們將跟踪朋友的生日,並能夠根據他們的姓名查找該信息。在您的文件中創建一個名稱和生日字典。當您運行程序時,應要求用戶輸入名稱,並將該人的生日返回給他們。交互應如下所示:

>>> Welcome to the birthday dictionary. We know the birthdays of:
Albert Einstein
Benjamin Franklin
Ada Lovelace
>>> Who's birthday do you want to look up?
Benjamin Franklin
>>> Benjamin Franklin's birthday is 01/17/1706.

Sample solution 樣品溶液

One reader does the basics: 一位讀者會做基礎:

if __name__ == '__main__':

    birthdays = {
        'Albert Einstein': '03/14/1879',
        'Benjamin Franklin': '01/17/1706',
        'Ada Lovelace': '12/10/1815',
        'Donald Trump': '06/14/1946',
        'Rowan Atkinson': '01/6/1955'}

    print('Welcome to the birthday dictionary. We know the birthdays of:')
    for name in birthdays:
        print(name)

    print('Who\'s birthday do you want to look up?')
    name = input()
    if name in birthdays:
        print('{}\'s birthday is {}.'.format(name, birthdays[name]))
    else:
        print('Sadly, we don\'t have {}\'s birthday.'.format(name))

And here is another reader submission: 這是另一位讀者的來稿:
import time
Birthdays ={
    "Albert Einstein": "14/3/1889",
    "Bill Gates": "28/10/1955",
    "Steve Jobs": "24/2/1955",
}
print("Welcome to the Birthday game ! We have the birthdays to:")
time.sleep(1)
for x in Birthdays:
    print(x)
    time.sleep(0.7)
choice= input("\nWho's birthday do you want to look up?")

if choice in Birthdays:
    print("The birthday of {} is: ".format(choice))
    print(Birthdays[choice])
 

String formatting 字符串格式 << Previous Next >> Tic Tac Toe Draw 井字遊戲抽獎

Copyright © All rights reserved | This template is made with by Colorlib